package tiny_file

import (
	"github.com/google/uuid"
	"time"
)

type Idx struct {
	Id      int64     `gorm:"column:id;primary_key;NOT NULL;" json:"id"`
	PieceId uuid.UUID `gorm:"column:piece_id;index;NOT NULL;" json:"piece_id"`
	File    string    `gorm:"column:file;size:6;index"`
	Pos     int64     `gorm:"column:pos;default:0;"`
	Space   int       `gorm:"column:space;default:0;"`
	Expire  int       `gorm:"column:expire;default:0"`
	Md5     []byte    `gorm:"column:md5;"`
	Del     uint8     `gorm:"column:del;default:0;"`
	Tmp     uint8     `gorm:"column:tmp;default:0;"`
}
type LargeFileInfo struct {
	File        string `gorm:"column:file;primary_key:size:6"`
	LastPos     int64  `gorm:"column:last_pos;default:0;"`
	Count       int64  `gorm:"column:count;default:0;"`
	LastCleanup int64  `gorm:"column:last_cleanup;default:0" json:"last_cleanup"`
}

func (idx *Idx) ExpiredOrDel() bool {
	if idx == nil {
		return true
	}
	if idx.Del == 1 || (idx.Expire > 0 && int64(idx.Expire) < time.Now().Unix()) {
		return true
	}
	return false
}
